package com.xxjh.auth.common.vo;

import com.xxjh.auth.common.enums.ResultCode;
import lombok.Data;

/**
 * @author CHENCHEN
 * @description
 * @company 新兴际华科技(天津)有限公司
 * @create 2024-11-20 13:50
 */
@Data
public class CommonVO<T> {
    /** 错误码 */
    private Integer code;

    /** 错误消息 */
    private String msg;

    /** 响应数据 */
    private T data;

    public CommonVO(ResultCode status) {
        this.code = status.getCode();
        this.msg = status.getMsg();
    }

    public CommonVO(Integer code, String message) {
        this.code = code;
        this.msg = message;
    }

    public CommonVO(ResultCode status, T data) {
        this.code = status.getCode();
        this.msg = status.getMsg();
        this.data = data;
    }

    //成功——无返回数据
    public static CommonVO SUCCESS = new CommonVO(ResultCode.SUCCESS);

    //成功——有返回数据
    public static CommonVO success(ResultCode status, Object data){
        return new CommonVO<>(status, data);
    }

    //失败——无返回数据
    public static CommonVO FAIL = new CommonVO(ResultCode.FAIL);

    //失败——有返回数据
    public static CommonVO FAIL(ResultCode status, Object data){
        return new CommonVO(status, data);
    }

    //异常——无返回数据
    public static CommonVO EXCEPTION = new CommonVO(ResultCode.SERVERERROR);

    //异常——无返回数据
    public static CommonVO exception(Integer code, String message){
        return new CommonVO(code, message);
    }
}
